package flex.cc.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import flex.cc.base.dto.LoginAuthDto;
import flex.cc.core.support.BaseController;
import flex.cc.system.entity.DictCodeEntity;
import flex.cc.system.service.DictCodeService;
import flex.cc.system.vo.DictCodeVo;
import flex.cc.system.vo.DictOptionVo;
import flex.cc.wrapper.WrapMapper;
import flex.cc.wrapper.Wrapper;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * @author lmq
 * @email limengqi@sinosoft.com.cn
 * @date 2020-09-18 16:04:05
 */
@RestController
@RequestMapping("/uac/dictcode")
public class DictCodeController extends BaseController{
    @Autowired
    private DictCodeService dictCodeService;
    
    /**
     * 保存或修改数据字典副类型
     * @return the wrapper
     */
    @PostMapping(value = "/saveOrUpdateDictCode")
    @ApiOperation(httpMethod = "POST", value = "保存或修改数据字典副类型")
    public Wrapper<String> saveOrUpdateDictCode(@RequestBody DictCodeVo vo) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	String result = dictCodeService.saveOrUpdateDictCode(vo,loginAuthDto);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 查询数据字典副类型-打开编辑type页面
     * @return the wrapper
     */
    @PostMapping(value = "/searchAllCode")
    @ApiOperation(httpMethod = "POST", value = "查询数据字典副类型-打开编辑type页面")
    public Wrapper<List<DictCodeEntity>> searchAllCode(@RequestBody DictCodeEntity dictCodeEntity) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	List<DictCodeEntity> result = dictCodeService.searchAllCode(dictCodeEntity,loginAuthDto);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 根据typeCode查询数据字典副类型-打开编辑type页面
     * @return the wrapper
     */
    @GetMapping(value = "/searchAllCodeByTypeCode/{typeCode}/{typeVersion}")
    @ApiOperation(httpMethod = "GET", value = "查询数据字典副类型-打开编辑type页面")
    public Wrapper<List<DictCodeEntity>> searchAllCodeByTypeCode(@PathVariable(value = "typeCode") String typeCode,
    		@PathVariable(value = "typeVersion") int typeVersion) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	String comCode = loginAuthDto.getComCode();
    	List<DictCodeEntity> result = dictCodeService.searchCodeByTypeList(typeCode,typeVersion,comCode);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 根据typeCode查询数据字典副类型-打开编辑type页面
     * @return the wrapper
     */
    @PostMapping(value = "/getdictCodeList")
    @ApiOperation(httpMethod = "POST", value = "根据typeCode查询数据字典副类型-打开编辑type页面")
    public Wrapper<IPage<DictCodeEntity>> getdictCodeList(@RequestBody DictCodeEntity dictCodeEntity) {
    	IPage<DictCodeEntity> result = dictCodeService.getdictCodeList(dictCodeEntity);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 查询数据字典副类型-打开编辑code页面
     * @return the wrapper
     */
    @GetMapping(value = "/searchDictCodeById/{id}")
    @ApiOperation(httpMethod = "GET", value = "查询数据字典副类型-打开编辑code页面")
    public Wrapper<DictCodeEntity> searchDictCodeById(@PathVariable(value = "id") Long id) {
    	DictCodeEntity result = dictCodeService.getById(id);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 注销数据字典副类型
     * @return the wrapper
     */
    @PostMapping(value = "/updateDictTypeById")
    @ApiOperation(httpMethod = "POST", value = "注销数据字典副类型")
    public Wrapper<String> updateDictTypeById(@RequestBody DictCodeEntity dictCodeEntity) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	String result = dictCodeService.updateDictTypeById(dictCodeEntity,loginAuthDto);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 删除code
     * @return the wrapper
     */
    @GetMapping(value = "/deleteDictCodeById/{id}")
    @ApiOperation(httpMethod = "GET", value = "删除code")
    public Wrapper<Boolean> deleteDictCodeById(@PathVariable(value = "id") Long id) {
    	LoginAuthDto loginAuthDto = getLoginAuthDto();
    	Boolean result = dictCodeService.deleteDictCodeById(id,loginAuthDto);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 根据type查询数据字典code，用来显示下拉选项
     * @return the wrapper
     */
    @GetMapping(value = "/getSelectOptions/{dicType}/{validStatus}")
    @ApiOperation(httpMethod = "GET", value = "根据type查询数据字典code，用来显示下拉选项")
    public Wrapper<List<DictOptionVo>> getSelectOptions(@PathVariable(value = "dicType") String dicType,
    		@PathVariable(value = "validStatus") String validStatus) {
    	List<DictOptionVo> result = dictCodeService.getSelectOptions(dicType, validStatus);
    	return WrapMapper.ok(result);
    }
    
    /**
     * 查询行政区划下拉选项的值
     * @return the wrapper
     */
    @GetMapping(value = "/getAdmOptions/{parentId}")
    @ApiOperation(httpMethod = "GET", value = "查询行政区划下拉选项的值")
    public Wrapper<List<DictOptionVo>> getAdmOptions(@PathVariable(value = "parentId") String parentIds) {
    	List<DictOptionVo> result = dictCodeService.getAdmOptions(parentIds);
    	return WrapMapper.ok(result);
    }
}
